package com.zhong.gang.app.ui.message;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.zhong.gang.app.R;
import com.zhong.gang.app.databinding.LayoutRecyclerviewBinding;
import com.zhong.gang.app.ui.examine.payment.PayMentAct;
import com.zhong.gang.app.ui.examine.price.PriceAct;
import com.zhong.gang.app.ui.waidiao.detail.WaiDiaoDetailAct;
import com.zhong.gang.app.ui.zhongzhuan.shou.ZhongZhuanShouAct;
import com.zhong.gang.app.ui.zhuchang.changsure.FaHuoChangAct;
import com.zhong.gang.app.ui.zhuchang.detail.ZhuChangDetailAct;
import com.zhong.gang.applib.base.act.ActBaseRefresh;
import com.zhong.gang.applib.http.BaseDataBean;
import com.zhong.gang.applib.http.callback.DataCallBack;
import com.zhong.gang.applib.modle.ListBean;

import java.util.ArrayList;

public class MessageAct extends ActBaseRefresh<LayoutRecyclerviewBinding,MessageAdapter>implements MessageAdapter.OnItemClickListener {
    private MessagePresenter presenter;
    @Override
    public int LayoutRes() {
        return R.layout.layout_recyclerview;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "通知消息";
    }

    @Override
    public void initView() {
        presenter = new MessagePresenter();
        bind.recycler.setLayoutManager(new LinearLayoutManager(this));
        initrefrsh(bind.pullto,new MessageAdapter(),bind.recycler);
        adapter.setOnItemClickListener(this);
        getData();
    }

    @Override
    public void getData() {
        super.getData();
        presenter.getList(this,page,new ActCallBack<BaseDataBean<ListBean<MessageBean>>>(){
            @Override
            public void onResponse(BaseDataBean<ListBean<MessageBean>> data) throws Exception {
                super.onResponse(data);
                setData(data.getResult().getRecords());
            }

            @Override
            public void onError(String str) {
                showMainFragemt();
                setData(new ArrayList<MessageBean>());
            }
        });
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        MessageBean messageBean = (MessageBean) adapter.getItem(position);
        ((MessageBean) adapter.getItem(position)).setReaded(true);
        adapter.notifyItemChanged(position);
        presenter.setRead(this,messageBean.getId(),new DataCallBack<BaseDataBean<String>>());
        switch (messageBean.getType()){
            case 1:
            case 3://到厂确认详情
                FaHuoChangAct.openAct(this,messageBean.getForeignId());
                break;
            case 2://中转库收货
                ZhongZhuanShouAct.openAct(this,messageBean.getForeignId());
                break;
            case 4://价格审核
                PriceAct.openAct(this,messageBean.getForeignId());
                break;
        }
    }
}
